<?php

namespace app\model;

use think\facade\Db;
use think\Model;

class AdminModel extends Model{

    protected $table ="admin";

    protected $pk = 'aid';

    private $redisModel;

    private $cacheKey="admin:";

    private $cacheTime=5184000;



    public function __construct()
    {
        parent::__construct();

        $this->redisModel = new RedisModel();
    }

    /*
     * 检查账号是不是
     * */
    public function getInfo($username){
        $where =[];
        $where[] = ['username','=',$username];
        return Db::name('admin')->where($where)->find();
    }




    /*
* 获取缓存
* */
    public function getCache($token){
        return  $this->redisModel->get( $this->cacheKey.$token);
    }



    /*
     * 设置缓存
     * */
    public function setCache($info){
        return  $this->redisModel->set($this->cacheKey . $info['token'],json_encode($info,256),1800);
    }




    /*
     * 删除缓存
     * */
    public function delCahce($token){
        if(empty($token)) return false;
        return  $this->redisModel->delete($this->cacheKey . $token);
    }



    /*
     * 删除全部缓存
     * */
    public function delAllCache(){
        return  $this->redisModel->deleteAll($this->cacheKey . "*");
    }

}